New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

html-validator

Package Overview
Dependencies
Maintainers
2
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-validator

Validate html using validator.w3.org/nu

  • 4.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19K
increased by2.71%
Maintainers
2
Weekly downloads
 
Created
Source

Build Status Coverage Status js-standard-style

html-validator

A Node.js module for validating html using validator.w3.org/nu

Requires Node >= 8.16.0 for older versions use v3.1.3

Module

Supports the following modes from Validator.nu Web Service Interface

  • Document URL as a GET parameter; the service retrieves the document by URL over HTTP or HTTPS.
  • Document POSTed as the HTTP entity body; parameters in query string as with GET.

Installation

$ npm i html-validator

Usage

Create an options object.

format This is the formatting of the returned data. It supports json (default), html, xhtml, xml, gnu and text.

validator You can override the default validator as long as it exposes the same REST interface.

url/data The url to the page you want to validate or the data you want validated. Can be an HTML, CSS or SVG document.

ignore String or array of strings you want the checker to remove in the response

isLocal Set this to true if you want to validate local urls

isFragment Set this to true if your data input is not a complete document

(async () => {
  const validator = require('html-validator')
  const options = {
  url: 'http://url-to-validate.com',
  format: 'text'
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

data The html you want to validate

(async () => {
  const validator = require('html-validator')
  const { readFileSync } = require('fs')
  const options = {
  url: 'http://url-to-validate.com',
  format: 'text',
  data: readFileSync('file-to-validate.html', 'utf8')
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

validator You can override the default validator as long as it exposes the same REST interface.

(async () => {
  const validator = require('html-validator')
  const options = {
  url: 'http://url-to-validate.com',
  validator: 'http://html5.validator.nu',
  format: 'text'
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

ignore String or array of strings you want the checker to remove in the response. Requires format = text

(async () => {
  const validator = require('html-validator')
  const options = {
  url: 'http://url-to-validate.com',
  format: 'text',
  ignore: 'Error: Stray end tag “div”.'
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

headers Object of headers to pass in with the url request

(async () => {
  const validator = require('html-validator')
  const options = {
  url: 'http://url-to-validate.com',
  format: 'text',
  headers: {foo:"bar"}
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

isLocal Set this to true if you want to validate local urls. Will lookup page and send data to validator

(async () => {
  const validator = require('html-validator')
  const options = {
    url: 'http://url-to-validate.com',
    format: 'text',
    isLocal: true
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

isFragment Set this to true if you want to validate something that is not a complete document

(async () => {
  const validator = require('html-validator')
  const options = {
    data: '<p>This is a fragment</p>',
    isFragment: true
  }
  
  try {
    const result = await validator(options)
    console.log(result)
  } catch (error) {
    console.error(error)
  }
})()

License

MIT

Keywords

FAQs

Package last updated on 20 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc